package cn.hs.service.impl;

import cn.hs.entity.CourseReply;
import cn.hs.mapper.CourseReplyMapper;
import cn.hs.mapper.UserMapper;
import cn.hs.service.CourseReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CourseReplyServiceImpl
 * @Description TODO
 * @Author wsh
 * @Date 2024年10月28日 14:31
 * @Version 1.0
 */
@Service
public class CourseReplyServiceImpl implements CourseReplyService {
    @Autowired
    private CourseReplyMapper courseReplyMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<CourseReply> selectByTalkId(Integer talkId) {
        List<CourseReply> list = courseReplyMapper.selectAllByTalkId(talkId);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setUserName(userMapper.selectById(list.get(i).getUserId()).getUsername());
        }
        return list;
    }

    @Override
    public int insert(CourseReply courseReply) {
        return courseReplyMapper.insertAll(courseReply);
    }
}
